#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "global.h"
#include "server_global.h"
#include "dp_config.h"

static int search_dpfile(void);
static int dp_init_variables(void);

/* Things reset to zero */
static int dp_init_variables(void)
{
    dp_version = 0;
    server_name = NULL;
    basedir = datadir = logdir = NULL;
    table_partitions = 0;
    max_databases = default_max_databases;
    max_tables = default_max_tables;
    max_table_partitions = default_max_table_partitions;
    return 0;
}

static int search_dpfile(void)
{
    uint len;
    char *filepath;
    filepath = (char *)malloc(0xff);
    if (NULL == filepath)
        return 1;
    memset(filepath, 0, 0xff);
  
    if (strlen(basedir) > 0xff - 6)
        return 1;
    len = snprintf(filepath, 0xff, "%s/%s", basedir, "dp.ini");
    if ( len < strlen(basedir) + 6)
        return 1;
    dpfile = filepath;
    return 0;
}

char basedir_tmp[] = "/home/shell/.netbeans/remote/172.17.4.49/bjyw-tangc-Windows-x86/F/Dolphin-Princess";
int dp_init_server(void)
{
    dp_init_variables();
     basedir = basedir_tmp;
    if (search_dpfile())
        return 1;
    if (load_dpfile())
        return 1;
    return 0;
}
/* END FILE */
